package com.example.dy.pay.conf;

import com.alipay.v3.ApiClient;
import com.alipay.v3.ApiException;
import com.alipay.v3.util.model.AlipayConfig;
import jakarta.annotation.PostConstruct;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.alipay.v3.Configuration.getDefaultApiClient;

@Configuration
public class ClientConf {

//    @Data
//    public static class Acc{
//        private String serverUrl;
//    }

    @Autowired
    public void setAcc(AlipayConfig acc) {
        this.acc = acc;
    }

    @Configuration
    public static class CC {
        @Bean
        @ConfigurationProperties(prefix = "pay.ali")
        public AlipayConfig alipayConfig() {
            return new AlipayConfig();
        }
    }

    //
    private AlipayConfig acc;

    //https://github.com/alipay/alipay-sdk-java-all/blob/master/v3/README.md
    //https://opendocs.alipay.com/open-v3/065bsc
    @PostConstruct
    public void init() throws ApiException {
        ApiClient apiClient = getDefaultApiClient();
//设置网关地址
//        apiClient.setBasePath(acc.getServerUrl());
//设置alipayConfig参数（全局设置一次）
//        AlipayConfig alipayConfig = new AlipayConfig();
////设置应用ID
//        alipayConfig.setAppId(APPID);
////设置应用私钥
//        alipayConfig.setPrivateKey(PRIVATE_KEY);
////设置支付宝公钥
//        alipayConfig.setAlipayPublicKey(ALIPAY_PUBLIC_KEY);
        apiClient.setAlipayConfig(acc);
    }
}
